package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.NewsDto;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author itheima
 * @since 2022-07-29
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;


    /**
     * 分页查询当前自媒体文章列表
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult queryByPage(@RequestBody WmNewsPageDto dto){
        return wmNewsService.queryByPage(dto);
    }


    /**
     * 提交自媒体文章
     * @param dto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        return wmNewsService.submit(dto);
    }

    /**
     * 根据文章ID查询文章详情信息
     * @param id 文章ID
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable("id") Integer id) {
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 人工审核列表
     * @param newsDto
     * @return
     */
    @PostMapping("findPageByName")
    public PageResponseResult findPageByName(@RequestBody NewsDto newsDto){
        return wmNewsService.findPageByName(newsDto);
    }

    /**
     * 获取审核文章详情
     * @param id
     * @return
     */
    @GetMapping("findNewsVoById/{id}")
    public ResponseResult findNewsVoById(@PathVariable("id") Integer id){
        return ResponseResult.okResult( wmNewsService.getById(id));
    }

    /**
     * 文章审核通过
     * @param newsDto
     * @return
     */
    @PostMapping("auth_pass")
    public ResponseResult authPass(@RequestBody NewsDto newsDto){
        return wmNewsService.authPass(newsDto);
    }
    /**
     * 文章审核拒绝
     * @param newsDto
     * @return
     */
    @PostMapping("auth_fail")
    public ResponseResult authFail(@RequestBody NewsDto newsDto){
        return wmNewsService.authFail(newsDto);
    }
    /**
     * 变更自媒体文章上下架状态
     * @param dto 自媒体文章ID，上下架状态
     * @return
     */
    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }
}
